﻿using BigEgg.Framework.UnitTesting;
using FMStudio.Documents.TemplateDocument.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FMStudio.Documents.TemplateDocument.Test
{
    [TestClass]
    public class ItemTemplateDocumentTest
    {
        private string TestPath1 = Path.Combine(Environment.CurrentDirectory, "Template1.fmstemplate");
        private string TestPath2 = Path.Combine(Environment.CurrentDirectory, "Template2.fmstemplate");


        [TestInitialize]
        public void TestCleanup()
        {
            if (File.Exists(TestPath1))
                File.Delete(TestPath1);
            if (File.Exists(TestPath2))
                File.Delete(TestPath2);
        }


        [TestMethod]
        public void DocumentTest()
        {
            ItemTemplateDocument document = new ItemTemplateDocument();

            Assert.AreEqual(TemplateType.Item, document.Type);
            Assert.IsNotNull(document.TemplateContent);
        }

        [TestMethod]
        public void DocumentModifyTest()
        {
            TemplateDocumentType documentType = new TemplateDocumentType();
            ItemTemplateDocument document = documentType.New(TestPath1, TemplateType.Item) as ItemTemplateDocument;
            documentType.Save(document);

            Assert.IsFalse(document.IsModified);
            AssertHelper.PropertyChangedEvent(document, x => x.IsModified,
                () => document.TemplateContent.Add(new Folder() { Name = "SomeFolder" }));
            Assert.IsTrue(document.IsModified);
        }
    }
}
